﻿#region Copyright 2008 - Evolution Systems.
//
// Author: José Rogério Ferreira dos Santos(joserogerio.santos@gmail.com)
// Date: 22/04/2009
// Time: 19:45
// All rights are reserved. Reproduction or transmission in whole or in part, in
// any form or by any means, eletronic, mechanical or otherwise, is prohibited
// without the prior written permission of the author.
//
// Filename: ${FILE_NAME}.cs
#endregion
using System;
using System.Collections.Generic;

namespace csharp.rad.finan
{
	/// <summary>
	/// Description of BillMvt.
	/// </summary>
	public class BillMvt : common.DefaultClass, common.IClass
	{
		#region private declarations
			private string _name;
			private string _agency_number;
			private string _agency_name;
			private string _agency_digit;
			private string _bill_number;
			private string _bill_digit;
			private string _active;
			private string _balance_date;
			private string _balance_value;
			private string _bank_id;
			private string _type_id;
			private string _company_id;
		#endregion
		
		#region properties
			public string name 
			{
				get { return _name; }
				set { _name = value; }
			}
			
			public string agencyNumber 
			{
				get { return _agency_number; }
				set { _agency_number = value; }
			}
			
			public string agencyName 
			{
				get { return _agency_name; }
				set { _agency_name = value; }
			}
			
			public string agencyDigit 
			{
				get { return _agency_digit; }
				set { _agency_digit = value; }
			}
			
			public string billNumber 
			{
				get { return _bill_number; }
				set { _bill_number = value; }
			}
			
			public string billDigit 
			{
				get { return _bill_digit; }
				set { _bill_digit = value; }
			}
			
			public string active 
			{
				get { return _active; }
				set { _active = value; }
			}
			
			public string balanceDate 
			{
				get { return _balance_date; }
				set { _balance_date = value; }
			}
			
			public string balanceValue 
			{
				get { return _balance_value; }
				set { _balance_value = value; }
			}
			
			public string bankId 
			{
				get { return _bank_id; }
				set { _bank_id = value; }
			}
			
			public string typeId 
			{
				get { return _type_id; }
				set { _type_id = value; }
			}
			
			public string companyId 
			{
				get { return _company_id; }
				set { _company_id = value; }
			}
		#endregion
		
		public BillMvt()
		{
			gsql.table = "finan.bill_mvt";
			_sequence  = "finan.bill_mvt_bill_mvt_id_seq";        
		}
		
		public void clear()
		{
			_id = string.Empty;
		}
		
		public override void get(System.Data.DataRow dr)
		{
			_id 					= dr["bill_mvt_id"].ToString();
			_name     			= dr["bill_mvt_name"].ToString(); 
			_agency_number    = dr["bill_mvt_agency_number"].ToString();
			_agency_name      = dr["bill_mvt_agency_name"].ToString();
			_agency_digit     = dr["bill_mvt_agency_digit"].ToString();
			_bill_number      = dr["bill_mvt_bill_number"].ToString();
			_bill_digit       = dr["bill_mvt_bill_digit"].ToString();
			_active    			= dr["bill_mvt_active"].ToString();
			_balance_date     = dr["bill_mvt_balance_date"].ToString();
			_balance_value    = dr["bill_mvt_balance_value"].ToString();
			_bank_id    		= dr["bill_mvt_bank_id"].ToString();
			_type_id    		= dr["bill_mvt_type_id"].ToString();
			_company_id       = dr["bill_mvt_company_id"].ToString();        
		}
		
		public override void setGsql()
		{
			gsql.setValue(_id            , "bill_mvt_id");
			gsql.setValue(_name          , "bill_mvt_name"); 
			gsql.setValue(_agency_number , "bill_mvt_agency_number");
			gsql.setValue(_agency_name   , "bill_mvt_agency_name"); 
			gsql.setValue(_agency_digit  , "bill_mvt_agency_digit"); 
			gsql.setValue(_bill_number   , "bill_mvt_bill_number");
			gsql.setValue(_bill_digit    , "bill_mvt_bill_digit"); 
			gsql.setValue(_active        , "bill_mvt_active");
			gsql.setValue(_balance_date  , "bill_mvt_balance_date"); 
			gsql.setValue(_balance_value , "bill_mvt_balance_value");
			gsql.setValue(_bank_id       , "bill_mvt_bank_id");
			gsql.setValue(_type_id       , "bill_mvt_type_id");
			gsql.setValue(_company_id    , "bill_mvt_company_id");
		}	
	}
    
	public class BillMvts : common.DefaultList, common.IList
	{		
		public BillMvts()
		{
			gsql.table = "finan.bill_mvt";
		}
		
		/*public List<BillMvt> items
		{
			get { return items; }
		}*/
		
		public BillMvt get(Int32 index)
		{
			return (BillMvt)items[index];
		}
		
		public BillMvt get()
		{
			return (BillMvt)items[index];
		}		
		
		public bool fillList()
		{
			gsql.prepare();
			gsql.setValue("","*");
			gsql.conditionalWhere = "bill_mvt_company_id = "+Information.companyId;
			gsql.additionalWhere = "ORDER BY bill_mvt_name";
			
			return mountList();
		}
		
		private bool mountList()
		{
			Int32 tam;
			
			if (!gsql.execute())
				return false;
			
			tam = gsql.getRowCount();
			items.Clear();
			for (int i=0; i < tam; i++)
			{
				BillMvt aux = new BillMvt();
				aux.get(gsql.getRow(i));
				items.Add(aux);
			}
			return true;
		}
	}    	
}
